layui.config({
    base: "js/"
}).use(['form', 'element', 'layer', 'jquery','upload'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        element = layui.element,
        upload = layui.upload,
        $ = layui.jquery;

    //上传缩略图
    upload.render({
        elem: '.thumbBox',
        url: '/up/lay',
        done: function(res, index, upload){
            var src = res.data.src;
            $("#headimg").val(src);

            $('.thumbImg').attr('src',src);
            $('.thumbBox').css("background","#fff");
        }
    });

    form.on("submit(saveInfo)",function(data){

        var options = {
            dataType: "json",
            success: function (data) {
                if(data && data.code==0){
                    layer.msg("更新信息成功~",{icon:6});
                }else{
                    layer.msg(data.msg?data.msg:"更新信息失败~",{icon:5});
                }

            },
            error: function (data) {
                layer.msg(data.msg?data.msg:"更新信息失败~");
            },
            complete:function () {
                window.location.reload();
            }
        };
        $("#infoForm").ajaxSubmit(options);
    })
})
